const pathToRegexp = require('path-to-regexp')
var regexp_1 = pathToRegexp('/foo/:bar')// /^\/foo\/([^\/]+?)(?:\/)?$/i
regexp_1.exec('/foo/barrrr')//匹配成功 =>RegExpExecArray [ '/foo/barrrr', 'barrrr', index: 0, input: '/foo/barrrr' ]
regexp_1.exec('/bazzzz')//匹配失败 => null

var regexp_2 = pathToRegexp('/foo/:bar*')
regexp_2.exec('/foo/a/b/c')// => [ '/foo/a/b/c', 'a/b/c', index: 0, input: '/foo/a/b/c' ]
regexp_2.exec('/foo')// => [ '/foo', undefined, index: 0, input: '/foo' ]

var regexp_3 = pathToRegexp('/foo/:bar+')
regexp_3.exec('/foo/a/b/c')// => [ '/foo/a/b/c', 'a/b/c', index: 0, input: '/foo/a/b/c' ]
regexp_3.exec('/foo')// => null

var regexp_4 = pathToRegexp('/foo/:bar?')
regexp_4.exec('/foo/a')// => [ '/foo/a', 'a', index: 0, input: '/foo/a' ]
regexp_4.exec('/foo/a/b/c')// => null
regexp_4.exec('/foo')// => [ '/foo', undefined, index: 0, input: '/foo' ]

var regexp_5 = pathToRegexp('/icon-:foo(\\d+).png')
regexp_5.exec('/icon-123.png')// => [ '/icon-123.png', '123', index: 0, input: '/icon-123.png' ]
regexp_5.exec('/icon-abc.png')// null

var regexp_5 = pathToRegexp('/icon-(\\d+).png')
regexp_5.exec('/icon-123.png')// => [ '/icon-123.png', '123', index: 0, input: '/icon-123.png' ]
regexp_5.exec('/icon-abc.png')// null

var keys = []
var regexp_6 = pathToRegexp('/:foo/icon-(\\d+).png',keys)
regexp_6.exec('/home/icon-123.png')// => [ '/icon-123.png', '123', index: 0, input: '/icon-123.png' ]
regexp_6.exec('/about/icon-abc.png')// null
console.log(keys) 
/**
keys output =>
[ { name: 'foo',
    prefix: '/',
    delimiter: '/',
    optional: false,
    repeat: false,
    partial: false,
    pattern: '[^\\/]+?' },
  { name: 0,
    prefix: '',
    delimiter: '/',
    optional: false,
    repeat: false,
    partial: false,
    pattern: '\\d+' } ]
*/

var tokens = pathToRegexp.parse('/foo/:baz/icon-(\\d+).png')
console.log(tokens)
/**
tokens output =>
[ '/foo',
  { name: 'baz',
    prefix: '/',
    delimiter: '/',
    optional: false,
    repeat: false,
    partial: false,
    pattern: '[^\\/]+?' },
  '/icon-',
  { name: 0,
    prefix: '',
    delimiter: '/',
    optional: false,
    repeat: false,
    partial: false,
    pattern: '\\d+' },
  '.png' ]
*/
var regexp_7 = pathToRegexp.tokensToRegExp(tokens)
console.log(regexp_7.exec('/foo/bazzz/icon-123.png'))//[ '/foo/bazzz/icon-123.png','bazzz','123',... ]
var toPathWithTokens = pathToRegexp.tokensToFunction(tokens)
console.log(toPathWithTokens({baz:'bazzz',0:'123'})) // => /foo/bazzz/icon-123.png

var toPath = pathToRegexp.compile('/foo/:baz/icon-(\\d+).png')
toPath({baz:'bazzz',0:'123'})//=> /foo/bazzz/icon-123.png




